#pragma once
#include "hash.hpp"

namespace ys
{
	template<class K, class V>
	class unordered_map
	{
	public:
		struct MapKeyOfT
		{
			const K& operator()(const std::pair<K, V>& key)
			{
				return key.first;
			}
		};

		typedef typename hash_bocket<K, std::pair<const K, V>, MapKeyOfT>::iterator iterator;
		typedef typename hash_bocket<K, std::pair<const K, V>, MapKeyOfT>::const_iterator const_iterator;

		iterator begin() 
		{
			return _hash.begin();
		}

		iterator end() 
		{
			return _hash.end();
		}

		const_iterator cbegin() const
		{
			return _hash.cbegin();
		}

		const_iterator cend() const
		{
			return _hash.cend();
		}

		void insert(const std::pair<K, V>& val)
		{
			_hash.insert(val);
		}

		V& operator[](const K& key)
		{
			std::pair<iterator, bool> ret =  _hash.insert(std::make_pair(key, V()));
			return ret.first->second;
		}

	private:
		hash_bocket<K, std::pair<const K, V> , MapKeyOfT> _hash;
	};
}